// main.cpp
/****************************************************/
#include "Interpreter01.h"

#include <chrono>
#include <iostream>
#include <string>
#include <unordered_map>

int main()
{
    unordered_map<string, int> variables;
    std::string input;
    bool is_timeout = false;
    std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
    std::chrono::steady_clock::time_point end;

    while (true)
    {
        end = std::chrono::steady_clock::now();
        if (std::chrono::duration_cast<std::chrono::seconds>(end - start).count() >= 1)
        {
            std::cout << "超时！" << std::endl;
            is_timeout = true;
        }

        if (cin.rdbuf()->in_avail() > 0 || is_timeout)
        {
            if(!is_timeout)
            {
            getline(cin, input);
            }
            else
            {
                input  = "1+2+3+4+5+6+7+8+9";
            }
            std::cout << "input:" << input << std::endl;
            Interpreter interpreter(input);
            variables[input] = interpreter.interpret();
            std::cout << "result:" << variables[input] << std::endl;
            break;
        }
    }

    return 0;
}